using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;

namespace Microsoft.EntityFrameworkCore.Metadata.Conventions;

public class DmStoreGenerationConvention : StoreGenerationConvention
{
	public DmStoreGenerationConvention([NotNull] ProviderConventionSetBuilderDependencies dependencies, [NotNull] RelationalConventionSetBuilderDependencies relationalDependencies)
		: base(dependencies, relationalDependencies)
	{
	}

	public override void ProcessPropertyAnnotationChanged(IConventionPropertyBuilder propertyBuilder, string name, IConventionAnnotation annotation, IConventionAnnotation oldAnnotation, IConventionContext<IConventionAnnotation> context)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Invalid comparison between Unknown and I4
		if (annotation == null || (oldAnnotation != null && ((IAnnotation)oldAnnotation).Value != null))
		{
			return;
		}
		bool flag = (int)annotation.GetConfigurationSource() != 2;
		switch (name)
		{
		case "Relational:DefaultValue":
			if (propertyBuilder.HasValueGenerationStrategy(null, flag) == null && RelationalPropertyBuilderExtensions.HasDefaultValue(propertyBuilder, (object)null, flag) != null)
			{
				context.StopProcessing();
				return;
			}
			break;
		case "Relational:DefaultValueSql":
			if (propertyBuilder.HasValueGenerationStrategy(null, flag) == null && RelationalPropertyBuilderExtensions.HasDefaultValueSql(propertyBuilder, (string)null, flag) != null)
			{
				context.StopProcessing();
				return;
			}
			break;
		case "Relational:ComputedColumnSql":
			if (propertyBuilder.HasValueGenerationStrategy(null, flag) == null && RelationalPropertyBuilderExtensions.HasComputedColumnSql(propertyBuilder, (string)null, flag) != null)
			{
				context.StopProcessing();
				return;
			}
			break;
		case "Dm:ValueGenerationStrategy":
			if (((RelationalPropertyBuilderExtensions.HasDefaultValue(propertyBuilder, (object)null, flag) == null) | (RelationalPropertyBuilderExtensions.HasDefaultValueSql(propertyBuilder, (string)null, flag) == null) | (RelationalPropertyBuilderExtensions.HasComputedColumnSql(propertyBuilder, (string)null, flag) == null)) && propertyBuilder.HasValueGenerationStrategy(null, flag) != null)
			{
				context.StopProcessing();
				return;
			}
			break;
		}
		this.ProcessPropertyAnnotationChanged(propertyBuilder, name, annotation, oldAnnotation, context);
	}

	protected override void Validate(IConventionProperty property, in StoreObjectIdentifier storeObject)
	{
		if (property.GetValueGenerationStrategyConfigurationSource().HasValue)
		{
			 property.GetValueGenerationStrategy(in storeObject);
			this.Validate(property,  storeObject);
		}
		else
		{
			this.Validate(property,  storeObject);
		}
	}
}
